﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admin_news_edit : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindType();
            string id = Request.QueryString["id"];

            NEWS.Model.News news = NEWS.BLL.News.GetNews(int.Parse(id));

            this.txtTitle.Text = news.Title;
            this.ddlType.SelectedValue = news.Menu.ToString();
            this.FreeTextBox1.Text = news.More;
            this.ddlState.SelectedValue = news.State.ToString();


        }

    }
    private void BindType()
    {
        ddlType.DataSource = NEWS.BLL.Menu.list();
        ddlType.DataTextField = "Title";
        ddlType.DataValueField = "Id";
        ddlType.DataBind();
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string id = Request.QueryString["id"];

        NEWS.Model.News news = NEWS.BLL.News.GetNews(int.Parse(id));
       
        news.Title = txtTitle.Text;
        news.Menu = int.Parse(ddlType.SelectedValue);
        news.More = FreeTextBox1.Text;
        news.State = int.Parse(ddlState.SelectedValue);
        news.Adddate = DateTime.Now;
        if (NEWS.BLL.News.update(news))
        {
            NEWS.JsHelper.Alert("更新成功");
        }
        else
            NEWS.JsHelper.Alert("更新失败");
    }
}